package com.lanou.tipsy.adapter.recommend;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lanou.tipsy.R;
import com.lanou.tipsy.entity.recommend.newest_recommend.newestSongsList.NewestList;
import com.lanou.tipsy.entity.singer.singerList.SingerRank;

import java.util.ArrayList;

/**
 * Created by FengJun on 15/10/22.
 * 歌手TOP100适配器
 */
public class NewestListAdapter extends BaseAdapter {
    private ArrayList<NewestList.PlazeAlbumListEntity.RMEntity.AlbumListEntity.ListEntity> datas;
    private NewestList.PlazeAlbumListEntity.RMEntity.AlbumListEntity.ListEntity entity;
    private Context context;
    private LayoutInflater inflater;

    public NewestListAdapter(ArrayList<NewestList.PlazeAlbumListEntity.RMEntity.AlbumListEntity.ListEntity> datas, Context context) {
        this.datas = datas;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return datas != null && datas.size() > 0 ? datas.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return datas != null && datas.size() > 0 ? datas.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_recommend_newest_list, null);
            viewHolder = new ViewHolder();
            viewHolder.imageView = (SimpleDraweeView) convertView.findViewById(R.id.draw_new_list);
            viewHolder.titleTv = (TextView) convertView.findViewById(R.id.tv_new_list_title);
            viewHolder.authorTv = (TextView) convertView.findViewById(R.id.tv_new_list_author);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        entity = (NewestList.PlazeAlbumListEntity.RMEntity.AlbumListEntity.ListEntity) getItem(position);
        String url = entity.getPic_big();//解析图片url
        if (url != null) {
            Uri uri = Uri.parse(url);
            viewHolder.imageView.setImageURI(uri);
        }
        viewHolder.titleTv.setText(entity.getTitle());
        viewHolder.authorTv.setText(entity.getAuthor());
        return convertView;
    }

    private class ViewHolder {
        private SimpleDraweeView imageView;
        private TextView titleTv, authorTv;
    }
}
